package com.scy.hospitalmanager.controller;

import com.github.pagehelper.PageInfo;
import com.scy.hospitalmanager.pojo.Patient;
import com.scy.hospitalmanager.pojo.PatientDailySigns;
import com.scy.hospitalmanager.service.impl.PatientServiceImpl;
import com.scy.hospitalmanager.until.GetPageNum;
import com.scy.hospitalmanager.until.ResponseMap;
import com.scy.hospitalmanager.until.SplitString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 患者接口
 * @ClassName: PatientController
 * @Author: KuonnjiArisu
 * @Date: 2021/8/18 9:36
 * @Version: 1.0
 */
@Controller
public class PatientController {
    @Autowired
    PatientServiceImpl patientService;


    /**
     * @return
     * @Author KuonnjiAirsu
     * @Description //TODO 获取每日体征
     * @Param Patient
     */
    @RequestMapping("/getDailySigns")
    @ResponseBody
    public ResponseMap getDailySigns(@RequestBody Patient patient) {
        if (patient.getPaId() != 0) {
            String getSpO2Num = patientService.getDailySignsByPatientId(patient).getPatientSpO2().getSpO2Number();
            String getNibpNum = patientService.getDailySignsByPatientId(patient).getPatientNibp().get(0).getNibpInfo();
            String getHr = patientService.getDailySignsByPatientId(patient).getPatientHr().getHrInfo();
            String getResp = patientService.getDailySignsByPatientId(patient).getPatientResp().getRespInfo();
            String getTemp = patientService.getDailySignsByPatientId(patient).getPatientTemp().getTempInfo();
            Map<String, Object> signMap = new HashMap<>();
            signMap.put("getSpO2Num", SplitString.ToList(getSpO2Num));
            signMap.put("getNibpNum", SplitString.ToList(getNibpNum));
            signMap.put("getHr",SplitString.ToList(getHr));
            signMap.put("getResp",SplitString.ToList(getResp));
            signMap.put("getTemp",SplitString.ToDoubleList(getTemp));
            return ResponseMap.OK(signMap);
        }
        return ResponseMap.NO();
    }


    /**
     * @return lis
     * @Author KuonnjiAirsu
     * @Description //TODO 获取所有患者
     * @Param null
     */
    @PostMapping("/getAllPatients")
    @ResponseBody
    public ResponseMap getAllPatients(@RequestBody GetPageNum getPageNum,@RequestHeader("token")String token) {
        getPageNum.setPageSize(15);
        if (getPageNum.getPageNo() == 0) {
            getPageNum.setPageNo(1);
        }
        return ResponseMap.OK(patientService.getAllPatients(getPageNum));
    }
    
    
    /**
     * @Author KuonnjiAirsu
     * @Description //TODO 通过id获取患者
     * @Param patient
     * @return patient
     */
    @PostMapping("/getPatientById")
    @ResponseBody
    public ResponseMap getPatientById(@RequestBody Patient patient){
        if (patientService.getPatientById(patient)!=null){
//            System.out.println(patient);
            return ResponseMap.OK(patientService.getPatientById(patient));
        }else {
            return ResponseMap.NO();
        }
    }

}
